package com.njsoft.bodyawakening.utils;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

/**
 * 设置TextView图片工具类
 */
public class DrawableUtils {
    /**
     * 设置
     * View.setCompoundDrawables(left, top, right, bottom);
     * @param context 内容
     * @param imgSrc  图片资源
     * @return 返回Drawable
     */
    public static Drawable getDrawable(Context context, int imgSrc) {
        Resources res = context.getResources();
        Drawable imgStudent = res.getDrawable(imgSrc);
//调用setCompoundDrawables时，必须调用Drawable.setBounds()方法,否则图片不显示
        imgStudent.setBounds(0, 0, imgStudent.getMinimumWidth(), imgStudent.getMinimumHeight());
        return imgStudent;
    }
}
